{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/middle-of-the-linked-list\n",
    "\n",
    "\n",
    "Runtime: 0 ms, faster than 100.00% of C++ online submissions for Middle of the Linked List.\n",
    "Memory Usage: 6.5 MB, less than 90.16% of C++ online submissions for Middle of the Linked List.\n",
    "\n",
    "\n",
    "```cpp\n",
    "struct ListNode {\n",
    "    int val;\n",
    "    ListNode *next;\n",
    "    ListNode() : val(0), next(nullptr) {}\n",
    "    ListNode(int x) : val(x), next(nullptr) {}\n",
    "    ListNode(int x, ListNode *next) : val(x), next(next) {}\n",
    "};\n",
    "\n",
    "class Solution {\n",
    "public:\n",
    "    ListNode* middleNode(ListNode* head) {\n",
    "        vector<ListNode*> l {head};\n",
    "        ListNode* node = head;\n",
    "        while (node != nullptr) {\n",
    "            node = node->next;\n",
    "            l.push_back(node);\n",
    "        }\n",
    "        int length = l.size();\n",
    "        int half = length / 2;\n",
    "        if (half * 2 == length) {\n",
    "            return l[half - 1];\n",
    "        } else {\n",
    "            return l[half];\n",
    "        }\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
